/*
 * Copyright (C) 2006-2012 TongYan Corporation
 * All rights reserved.
 *
 * @brief info:
 *
 * @author: 王哲成 - wangzhecheng@yeah.net
 * @date: 2021.05.25
 * @last modified: 2021-05-25 16:09
 *
 */

#include "../include/DampedNewton.hpp"

bool DampedNewton::updateSearchPoint(const ParamSet &param_set,
                                     Candidate &candidate) const {
  // 计算下降方向dk(负方向)
  Vector dk = -m_ptrTarFunc->gradientVector(candidate.first, param_set.dx());
  if (dk.squaredNorm() < m_dEpsilon * m_dEpsilon)
    return true;
  // 计算海塞矩阵Hx
  Matrix Hx = m_ptrTarFunc->HessianMatrix(candidate.first, param_set.dx());

  // Armijo法计算步长
  double lambda = Armijo(candidate.first, param_set.dx(), dk);

  // dx = H(x)^-1*dk
  candidate.first += lambda * Hx.colPivHouseholderQr().solve(dk);

  return false;
}
